package message

import (
	"github.com/romberli/go-util/config"
)

const (
	ErrPrintHelpInfo            = 400001
	ErrNotValidRole             = 400002
	ErrEmptyLogFileName         = 400003
	ErrNotValidLogFileName      = 400004
	ErrNotValidLogLevel         = 400005
	ErrNotValidLogFormat        = 400006
	ErrNotValidLogMaxSize       = 400007
	ErrNotValidLogMaxDays       = 400008
	ErrNotValidLogMaxBackups    = 400009
	ErrNotValidServerPort       = 400010
	ErrNotValidPidFile          = 400011
	ErrValidateConfig           = 400012
	ErrInitDefaultConfig        = 400013
	ErrReadConfigFile           = 400014
	ErrOverrideCommandLineArgs  = 400015
	ErrOverrideEnvironmentArgs  = 400016
	ErrAbsoluteLogFilePath      = 400017
	ErrInitLogger               = 400018
	ErrRotateLogFile            = 400019
	ErrBaseDir                  = 400020
	ErrInitConfig               = 400021
	ErrCheckServerPid           = 400022
	ErrCheckServerRunningStatus = 400023
	ErrServerIsRunning          = 400024
	ErrStartAsForeground        = 400025
	ErrSavePidToFile            = 400026
	Err
	ErrKillServerWithPid                       = 400027
	ErrKillServerWithPidFile                   = 400028
	ErrGetPidFromPidFile                       = 400029
	ErrSetSid                                  = 400030
	ErrRemovePidFile                           = 400031
	ErrNotValidDBAddr                          = 400032
	ErrNotValidDBName                          = 400033
	ErrNotValidDBUser                          = 400034
	ErrNotValidDBPass                          = 400035
	ErrNotValidDBPoolMaxConnections            = 400036
	ErrNotValidDBPoolInitConnections           = 400037
	ErrNotValidDBPoolMaxIdleConnections        = 400038
	ErrNotValidDBPoolMaxIdleTime               = 400039
	ErrNotValidDBPoolMaxWaitTime               = 400040
	ErrNotValidDBPoolMaxRetryCount             = 400041
	ErrNotValidDBPoolKeepAliveInterval         = 400042
	ErrInitConnectionPool                      = 400043
	ErrInitHTTPClient                          = 400044
	ErrInitHealthcheckBucket                   = 400045
	ErrNotValidServerReadTimeout               = 400046
	ErrNotValidServerWriteTimeout              = 400047
	ErrNotValidServerRouterAlternativeBasePath = 400048
	ErrNotValidServerAddr                      = 400049
	ErrNotValidPath                            = 400050
	ErrFieldNotExists                          = 400051
	ErrGetRawData                              = 400052
	ErrUnmarshalRawData                        = 400053
	ErrGenerateNewMapWithTag                   = 400054
	ErrMarshalData                             = 400055
	ErrTypeConversion                          = 400056
	ErrFieldNotExistsOrWrongType               = 400057
	ErrNotValidTimeLayout                      = 400058
	ErrNotValidTimeDuration                    = 400059
	ErrNotValidMetadataTableAnalyzeMinRole     = 400060
	ErrNotValidAlertSMTPFormat                 = 400061
	ErrNotValidAlertHTTPURL                    = 400062
	ErrNotValidAlertConfig                     = 400063
	ErrNotValidHealthcheckBucketCapacity       = 400064
	ErrNotValidHealthcheckBucketNum            = 400065
	ErrNotValidHealthcheckBucketInterval       = 400066
	ErrNotValidHealthcheckBucketMaxWaitTime    = 400067
	ErrEmptySoarBin                            = 400068
	ErrNotValidSoarBin                         = 400069
	ErrEmptySoarConfig                         = 400070
	ErrNotValidSoarConfig                      = 400071
	ErrEmptySoarTempDir                        = 400072
	ErrNotValidSoarTempDir                     = 400073
	ErrInitSoarTempDir                         = 400074
	ErrEmptySoarBlacklist                      = 400075
	ErrNotValidSoarBlacklist                   = 400076
	ErrGetResponseCode                         = 400077
	ErrSetResponseCode                         = 400078
	ErrNotValidServerRouterHTTPErrorCode       = 400079
	ErrNodeValidServerDeploymentAccessibleZone = 400080
	ErrNotValidServerCallbackAddr              = 400081
	ErrCloseHTTPResponseBody                   = 400082
	ErrWrongHTTPStatusCode                     = 400083
	ErrGinRecovery                             = 400084
)

func initErrorMessage() {
	Messages[ErrPrintHelpInfo] = config.NewErrMessage(DefaultMessageHeader, ErrPrintHelpInfo, "got message when printing help information")
	Messages[ErrNotValidRole] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogLevel, "role must be one of [server, agent], %s is not valid")
	Messages[ErrEmptyLogFileName] = config.NewErrMessage(DefaultMessageHeader, ErrEmptyLogFileName, "log file name could not be an empty string")
	Messages[ErrNotValidLogFileName] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogFileName, "log file name must be either unix or windows path format, %s is not valid")
	Messages[ErrNotValidLogLevel] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogLevel, "log level must be one of [debug, info, warn, message, fatal], %s is not valid")
	Messages[ErrNotValidLogFormat] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogFormat, "log format must be either text or json, %s is not valid")
	Messages[ErrNotValidLogMaxSize] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogMaxSize, "log max size must be between %d and %d, %d is not valid")
	Messages[ErrNotValidLogMaxDays] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogMaxDays, "log max days must be between %d and %d, %d is not valid")
	Messages[ErrNotValidLogMaxBackups] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidLogMaxBackups, "log max backups must be between %d and %d, %d is not valid")
	Messages[ErrNotValidServerPort] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerPort, "Server port must be between %d and %d, %d is not valid")
	Messages[ErrNotValidPidFile] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidPidFile, "pid file name must be either unix or windows path format, %s is not valid")
	Messages[ErrValidateConfig] = config.NewErrMessage(DefaultMessageHeader, ErrValidateConfig, "validate config failed")
	Messages[ErrInitDefaultConfig] = config.NewErrMessage(DefaultMessageHeader, ErrInitDefaultConfig, "init default configuration failed")
	Messages[ErrReadConfigFile] = config.NewErrMessage(DefaultMessageHeader, ErrReadConfigFile, "read config file failed")
	Messages[ErrOverrideCommandLineArgs] = config.NewErrMessage(DefaultMessageHeader, ErrOverrideCommandLineArgs, "override command line arguments failed")
	Messages[ErrOverrideEnvironmentArgs] = config.NewErrMessage(DefaultMessageHeader, ErrOverrideEnvironmentArgs, "override environment arguments failed")
	Messages[ErrAbsoluteLogFilePath] = config.NewErrMessage(DefaultMessageHeader, ErrAbsoluteLogFilePath, "get absolute path of log file failed. log file: %s")
	Messages[ErrInitLogger] = config.NewErrMessage(DefaultMessageHeader, ErrInitLogger, "initialize logger failed")
	Messages[ErrRotateLogFile] = config.NewErrMessage(DefaultMessageHeader, ErrRotateLogFile, "rotate log file failed")
	Messages[ErrBaseDir] = config.NewErrMessage(DefaultMessageHeader, ErrBaseDir, "get base dir of %s failed")
	Messages[ErrInitConfig] = config.NewErrMessage(DefaultMessageHeader, ErrInitConfig, "init config failed")
	Messages[ErrCheckServerPid] = config.NewErrMessage(DefaultMessageHeader, ErrCheckServerPid, "check server pid file failed")
	Messages[ErrCheckServerRunningStatus] = config.NewErrMessage(DefaultMessageHeader, ErrCheckServerRunningStatus, "check server running status failed")
	Messages[ErrServerIsRunning] = config.NewErrMessage(DefaultMessageHeader, ErrServerIsRunning, "pid file exists or server is still running. pid file: %s")
	Messages[ErrStartAsForeground] = config.NewErrMessage(DefaultMessageHeader, ErrStartAsForeground, "got message when starting das as foreground")
	Messages[ErrSavePidToFile] = config.NewErrMessage(DefaultMessageHeader, ErrSavePidToFile, "got message when writing pid to file")
	Messages[ErrKillServerWithPid] = config.NewErrMessage(DefaultMessageHeader, ErrKillServerWithPid, "kill server failed. pid: %d")
	Messages[ErrKillServerWithPidFile] = config.NewErrMessage(DefaultMessageHeader, ErrKillServerWithPidFile, "kill server with pid file failed. pid: %d, pid file: %s")
	Messages[ErrGetPidFromPidFile] = config.NewErrMessage(DefaultMessageHeader, ErrGetPidFromPidFile, "get pid from pid file failed. pid file: %s")
	Messages[ErrSetSid] = config.NewErrMessage(DefaultMessageHeader, ErrSetSid, "set sid failed when daemonizing server")
	Messages[ErrRemovePidFile] = config.NewErrMessage(DefaultMessageHeader, ErrRemovePidFile, "remove pid file failed. pid file: %s")
	Messages[ErrNotValidDBAddr] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBAddr, "database address must be formatted as host:port, %s is not valid")
	Messages[ErrNotValidDBName] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBName, "database name must be a string, %s is not valid")
	Messages[ErrNotValidDBUser] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBUser, "database user name must be a string, %s is not valid")
	Messages[ErrNotValidDBPass] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPass, "database password must be a string, %s is not valid")
	Messages[ErrNotValidDBPoolMaxConnections] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolMaxConnections, "database max connections must be between %d and %d, %d is not valid")
	Messages[ErrNotValidDBPoolInitConnections] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolInitConnections, "database initial connections must be between %d and %d, %d is not valid")
	Messages[ErrNotValidDBPoolMaxIdleConnections] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolMaxIdleConnections, "database max idle connections must be between %d and %d, %d is not valid")
	Messages[ErrNotValidDBPoolMaxIdleTime] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolMaxIdleTime, "database max idle time must be between %d and %d, %d is not valid")
	Messages[ErrNotValidDBPoolMaxWaitTime] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolMaxWaitTime, "database max wait time must be between %d and %d, %d is not valid")
	Messages[ErrNotValidDBPoolMaxRetryCount] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolMaxRetryCount, "database max retry count must be between %d and %d, %d is not valid")
	Messages[ErrNotValidDBPoolKeepAliveInterval] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidDBPoolKeepAliveInterval, "database keep alive interval must be between %d and %d, %d is not valid")
	Messages[ErrInitConnectionPool] = config.NewErrMessage(DefaultMessageHeader, ErrInitConnectionPool, "init connection pool failed")
	Messages[ErrInitHTTPClient] = config.NewErrMessage(DefaultMessageHeader, ErrInitHTTPClient, "init http client failed")
	Messages[ErrInitHealthcheckBucket] = config.NewErrMessage(DefaultMessageHeader, ErrInitHealthcheckBucket, "init healthcheck bucket failed")
	Messages[ErrNotValidServerReadTimeout] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerReadTimeout, "server read timeout must be between %d and %d, %d is not valid")
	Messages[ErrNotValidServerWriteTimeout] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerWriteTimeout, "server write timeout must be between %d and %d, %d is not valid")
	Messages[ErrNotValidServerRouterAlternativeBasePath] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerRouterAlternativeBasePath, "server router alternative base path must be started with slash(/), %s is not valid")
	Messages[ErrNotValidServerAddr] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerAddr, "server addr must be formatted as host:port, %s is not valid")
	Messages[ErrNotValidPath] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidPath, "the service role is %s, this path is not valid. role: %s, path: %s")
	Messages[ErrFieldNotExists] = config.NewErrMessage(DefaultMessageHeader, ErrFieldNotExists, "field does not exist. field name: %s")
	Messages[ErrGetRawData] = config.NewErrMessage(DefaultMessageHeader, ErrGetRawData, "get raw data from http body failed")
	Messages[ErrUnmarshalRawData] = config.NewErrMessage(DefaultMessageHeader, ErrUnmarshalRawData, "unmarshal raw data failed")
	Messages[ErrGenerateNewMapWithTag] = config.NewErrMessage(DefaultMessageHeader, ErrGenerateNewMapWithTag, "generate new map with tag %s failed")
	Messages[ErrMarshalData] = config.NewErrMessage(DefaultMessageHeader, ErrMarshalData, "marshal service failed")
	Messages[ErrTypeConversion] = config.NewErrMessage(DefaultMessageHeader, ErrTypeConversion, "type conversion failed")
	Messages[ErrFieldNotExistsOrWrongType] = config.NewErrMessage(DefaultMessageHeader, ErrFieldNotExistsOrWrongType, "field does not exist or is wrong type. field name: %s")
	Messages[ErrNotValidTimeLayout] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidTimeLayout, "time layout must be formatted as yyyy-MM-dd HH:mm:ss, %s is not valid")
	Messages[ErrNotValidTimeDuration] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidTimeDuration, "time duration must be formatted, e.g. such as 300ms, -1.5h or 2h45m, %s is not valid")
	Messages[ErrNotValidMetadataTableAnalyzeMinRole] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidMetadataTableAnalyzeMinRole, "metadata table analyze min role must be between %d and %d, %d is not valid")
	Messages[ErrNotValidAlertSMTPFormat] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidAlertSMTPFormat, "alert smtp format must be either text or html, %s is not valid")
	Messages[ErrNotValidAlertHTTPURL] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidAlertHTTPURL, "alert http url must be a url, %s is not valid")
	Messages[ErrNotValidAlertConfig] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidAlertConfig, "got error shen when converting to map[string]string")
	Messages[ErrNotValidHealthcheckBucketCapacity] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidHealthcheckBucketCapacity, "healthcheck bucket capacity must be greater than 0, %d is not valid")
	Messages[ErrNotValidHealthcheckBucketNum] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidHealthcheckBucketNum, "healthcheck bucket number must be greater than 0, %d is not valid")
	Messages[ErrNotValidHealthcheckBucketInterval] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidHealthcheckBucketInterval, "healthcheck bucket interval must be greater than 0, %d is not valid")
	Messages[ErrNotValidHealthcheckBucketMaxWaitTime] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidHealthcheckBucketMaxWaitTime, "healthcheck bucket max wait time must be greater than 0, %d is not valid")
	Messages[ErrEmptySoarBin] = config.NewErrMessage(DefaultMessageHeader, ErrEmptySoarBin, "soar binary path could not be an empty string")
	Messages[ErrNotValidSoarBin] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidSoarBin, "soar binary path must be either unix or windows path format, %s is not valid")
	Messages[ErrEmptySoarConfig] = config.NewErrMessage(DefaultMessageHeader, ErrEmptySoarConfig, "soar config path could not be an empty string")
	Messages[ErrNotValidSoarConfig] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidSoarConfig, "soar config path must be either unix or windows path format, %s is not valid")
	Messages[ErrEmptySoarTempDir] = config.NewErrMessage(DefaultMessageHeader, ErrEmptySoarTempDir, "soar query temporary directory could not be an empty string")
	Messages[ErrNotValidSoarTempDir] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidSoarTempDir, "soar query temporary directory must be either unix or windows path format, %s is not valid")
	Messages[ErrInitSoarTempDir] = config.NewErrMessage(DefaultMessageHeader, ErrInitSoarTempDir, "init soar query temporary directory failed. temporary directory: %s")
	Messages[ErrEmptySoarBlacklist] = config.NewErrMessage(DefaultMessageHeader, ErrEmptySoarBlacklist, "soar blacklist path could not be an empty string")
	Messages[ErrNotValidSoarBlacklist] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidSoarBlacklist, "soar blacklist path must be either unix or windows path format, %s is not valid")
	Messages[ErrGetResponseCode] = config.NewErrMessage(DefaultMessageHeader, ErrGetResponseCode, "get response code failed")
	Messages[ErrSetResponseCode] = config.NewErrMessage(DefaultMessageHeader, ErrSetResponseCode, "set response code failed")
	Messages[ErrNotValidServerRouterHTTPErrorCode] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerRouterHTTPErrorCode, "server router http error code must be either 200 or 500, %d is not valid")
	Messages[ErrNodeValidServerDeploymentAccessibleZone] = config.NewErrMessage(DefaultMessageHeader, ErrNodeValidServerDeploymentAccessibleZone, "server deployment accessible zone must be formatted as A.B.C, %s is not valid")
	Messages[ErrNotValidServerCallbackAddr] = config.NewErrMessage(DefaultMessageHeader, ErrNotValidServerCallbackAddr, "server callback addr must be formatted as host:port, %s is not valid")
	Messages[ErrCloseHTTPResponseBody] = config.NewErrMessage(DefaultMessageHeader, ErrCloseHTTPResponseBody, "close http response body failed")
	Messages[ErrWrongHTTPStatusCode] = config.NewErrMessage(DefaultMessageHeader, ErrWrongHTTPStatusCode, "got wrong http response status code. status code: %d, body: %s")
	Messages[ErrGinRecovery] = config.NewErrMessage(DefaultMessageHeader, ErrGinRecovery, "gin Recovery: panic recovered")
}
